import request from '@/config/axios'

export interface PageParam {
  merchantId?: string // 商户id
  deviceSn?: string // 设备Sn
  deviceNickname?: string // 设备名称
  modelType?:number // 设备类型
  status?:number // 设备状态
  online?:number // 设备是否在线 0-离线 1-在线
  createTime?:string[] // 设备创建时间mac
  pageNo:number // 页码，从 1 开始
  pageSize:number // 每页条数，最大值为 100
}

export interface Eqiutment{
  deviceSn: string, //设备序列号
  pkey:string, //设备KEY
  deviceNickname: string //设备备注名
}
export interface EqiutmentVo{
id: number, //主键ID
deviceNickname: string, //设备备注名
status: string, //设备状态：0-禁用 1-启用
voice: string, //语音播报配置
autoCut: string //自动切纸开关
}
export interface MatchEquitment{
  deviceSn:string,
  merchantId: string // 商户id
}
// 获得 设备 列表
export const getEquitmentPage = (params: PageParam) => {
  return request.get({ url: '/device/printer/page', params })
}
// 获得设备详情
export const getEquitment = (id: number) => {
  return request.get({ url: `/device/printer/get?id=${id}` })
}
// 创建设备
export const createEquitment = (data: Eqiutment) => {
  return request.post({ url: '/device/printer/create', data })
}
// 同步设备
export const matchEquitment = (deviceSn: string) => {
  return request.get({ url: `device/printer/sync?deviceSn=${deviceSn}` })
}
// 同步所有设备
export const matchEquitments = () => {
  return request.get({ url: '/device/printer/sync-all' })
}
// 更新设备
export const updateEquitment = (data: EqiutmentVo) => {
  return request.put({ url: '/device/printer/update', data })
}
// 删除设备
export const deleteEquitment = (id: number) => {
  return request.delete({ url: `/device/printer/delete?id=${id}` })
}
// 删除设备
export const deleteEquitmentBySn = (sn: string) => {
  return request.delete({ url: `/device/printer/deleteBySn?sn=${sn}` })
}

// 绑定商户
export const equitmentToShop = (data: MatchEquitment) => {
  return request.get({ url: `/api/merchant/device/bind?deviceSn=${data.deviceSn}&merchantId=${data.merchantId}` })
}
// 解除设备
export const quitEquitment = (deviceSn: string) => {
  return request.get({ url: `/api/merchant/device/unbind?deviceSn=${deviceSn}`})
}